#!/bin/sh
RTMEUSDIR=`pwd | sed 's/\/tools//'`
TMPDIR=/usr/local/src/OpenRTM
OPENRTM_SVNURL=http://openrtm.org/svnroot/OpenRTM-aist/branches/RELENG_1_1/OpenRTM-aist

if [ ! -e ${TMPDIR} ];
then
    mkdir -p $TMPDIR
fi

cd $TMPDIR
pwd
if [ ! -e ${TMPDIR}/OpenRTM-aist ];
then
    svn co $OPENRTM_SVNURL
else
    cd $TMPDIR/OpenRTM-aist; svn up
fi

cd $TMPDIR/OpenRTM-aist
sh build/autogen

if [ "`uname -m`" = "x86_64" ]; then
if [ "$ARCHDIR" = "Linux64" ]; then
echo "Linux64 ./configure without options"
./configure --prefix=/usr/local/
else
echo "add -m32 ./configure options on x86_64"
./configure CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 --prefix=/usr/local/
fi
else
echo "This is normal ./configure without options"
./configure --prefix=/usr/local/
fi
make
sudo make install

# sun-java6
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk
sudo update-java-alternatives -s java-6-sun

#add environmental variables to .bashrc.rtm
if [ -z"${ARCHDIR+xxx}" ];
    then
    OS=`/bin/uname | sed s/-.*//`
    if test ${OS} = "CYGWIN_NT"; 
    then
	ARCHDIR=Cygwin
    elif test ${OS} = "Linux";
    then
	ARCHDIR=Linux
    else
	echo "unsupported OS"
    fi
    echo "export ARCHDIR="$ARCHDIR >> $HOME/.bashrc.rtm
fi

echo " " >> $HOME/.bashrc.rtm
echo "#for rtmeus " >> $HOME/.bashrc.rtm
echo "export RTMEUSDIR="$RTMEUSDIR >> $HOME/.bashrc.rtm
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$RTMEUSDIR/RTMEus/Linux/lib" >> $HOME/.bashrc.rtm

